package com.x.Part8_多态;

/**
 * ClassName: Poly
 * Package: IntelliJ IDEA
 * Description:
 * Written by HanXu
 * Create 2023/10/17 19:20
 */
public class Poly {
    public static void main(String[] args) {
        Person p = new Students();
        p.run();//打印"跑操!"
    }
}

class Person{
    protected String name;

    public void run(){
        System.out.println("冲！");
    }

    @Override
    public String toString() {
        return "Person:name" + name;
    }

    //比较是否相等
    @Override
    public boolean equals(Object o){
        //判断o是否为Person类型
        if(o instanceof Person){
            Person p = (Person) o;
            return this.name.equals(p.name);
        }
        return false;
    }

    // 计算hash
    @Override
    public int hashCode() {
        return this.name.hashCode();
    }
}

class Students extends Person{
    @Override
    public void run(){
        System.out.println("跑操！");
    }
}
